<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>props</title>
  <script src="https://unpkg.com/react@16/umd/react.development.js"></script>
  <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
  <!-- 生产环境中不建议使用 -->
  <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>

  <script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/prop-types/15.8.1/prop-types.min.js"></script>
</head>

<body>
  <h2>年龄加1</h2>
  <!-- 容器 -->
  <div id="test1"></div>
  <div id="test2"></div>
  <div id="test3"></div>

  <script type="text/babel">
    //  创建组件
    class Person extends React.Component {
      // 直接写在里面，和 Person.propTypes 一样
      static propTypes = {
        name: PropTypes.string.isRequired,
        sex: PropTypes.string,
        age: PropTypes.number,
        speak: PropTypes.func,
      }

      static defaultProps = {
        sex: "未知",
        age: 18,
      }

      state = {}

      render() {
        console.log(this);
        let { name, age, sex } = this.props;
        return (
          <ul >
            <li>姓名: {name}</li>
            <li>年龄: {age + 1}</li>
            <li>性别: {sex}</li>
          </ul>
        )
      }
    }
    // name 必传
    // age 数字
    // sex 默认'男

    ReactDOM.render(<Person name="Jerry" />, document.getElementById("test1"))

  </script>

</body>

</html>
